<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Loop querying (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Loop querying (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Loop querying (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Loop-Analysis-and-Representation.html" rel="up" title="Loop Analysis and Representation">
<link href="Loop-manipulation.html" rel="next" title="Loop manipulation">
<link href="Loop-representation.html" rel="prev" title="Loop representation">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
span:hover a.copiable-link {visibility: visible}
ul.mark-bullet {list-style-type: disc}
-->
</style>


</head>

<body lang="en">
<div class="section-level-extent" id="Loop-querying">
<div class="nav-panel">
<p>
Next: <a href="Loop-manipulation.html" accesskey="n" rel="next">Loop manipulation</a>, Previous: <a href="Loop-representation.html" accesskey="p" rel="prev">Loop representation</a>, Up: <a href="Loop-Analysis-and-Representation.html" accesskey="u" rel="up">Analysis and Representation of Loops</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Loop-querying-1"><span>16.2 Loop querying<a class="copiable-link" href="#Loop-querying-1"> &para;</a></span></h3>
<a class="index-entry-id" id="index-Loop-querying"></a>

<p>The functions to query the information about loops are declared in
<samp class="file">cfgloop.h</samp>.  Some of the information can be taken directly from
the structures.  <code class="code">loop_father</code> field of each basic block contains
the innermost loop to that the block belongs.  The most useful fields of
loop structure (that are kept up-to-date at all times) are:
</p>
<ul class="itemize mark-bullet">
<li><code class="code">header</code>, <code class="code">latch</code>: Header and latch basic blocks of the
loop.
</li><li><code class="code">num_nodes</code>: Number of basic blocks in the loop (including
the basic blocks of the sub-loops).
</li><li><code class="code">outer</code>, <code class="code">inner</code>, <code class="code">next</code>: The super-loop, the first
sub-loop, and the sibling of the loop in the loops tree.
</li></ul>

<p>There are other fields in the loop structures, many of them used only by
some of the passes, or not updated during CFG changes; in general, they
should not be accessed directly.
</p>
<p>The most important functions to query loop structures are:
</p>
<ul class="itemize mark-bullet">
<li><code class="code">loop_depth</code>: The depth of the loop in the loops tree, i.e., the
number of super-loops of the loop.
</li><li><code class="code">flow_loops_dump</code>: Dumps the information about loops to a
file.
</li><li><code class="code">verify_loop_structure</code>: Checks consistency of the loop
structures.
</li><li><code class="code">loop_latch_edge</code>: Returns the latch edge of a loop.
</li><li><code class="code">loop_preheader_edge</code>: If loops have preheaders, returns
the preheader edge of a loop.
</li><li><code class="code">flow_loop_nested_p</code>: Tests whether loop is a sub-loop of
another loop.
</li><li><code class="code">flow_bb_inside_loop_p</code>: Tests whether a basic block belongs
to a loop (including its sub-loops).
</li><li><code class="code">find_common_loop</code>: Finds the common super-loop of two loops.
</li><li><code class="code">superloop_at_depth</code>: Returns the super-loop of a loop with
the given depth.
</li><li><code class="code">tree_num_loop_insns</code>, <code class="code">num_loop_insns</code>: Estimates the
number of insns in the loop, on GIMPLE and on RTL.
</li><li><code class="code">loop_exit_edge_p</code>: Tests whether edge is an exit from a
loop.
</li><li><code class="code">mark_loop_exit_edges</code>: Marks all exit edges of all loops
with <code class="code">EDGE_LOOP_EXIT</code> flag.
</li><li><code class="code">get_loop_body</code>, <code class="code">get_loop_body_in_dom_order</code>,
<code class="code">get_loop_body_in_bfs_order</code>: Enumerates the basic blocks in the
loop in depth-first search order in reversed CFG, ordered by dominance
relation, and breath-first search order, respectively.
</li><li><code class="code">single_exit</code>: Returns the single exit edge of the loop, or
<code class="code">NULL</code> if the loop has more than one exit.  You can only use this
function if <code class="code">LOOPS_HAVE_RECORDED_EXITS</code> is used.
</li><li><code class="code">get_loop_exit_edges</code>: Enumerates the exit edges of a loop.
</li><li><code class="code">just_once_each_iteration_p</code>: Returns true if the basic block
is executed exactly once during each iteration of a loop (that is, it
does not belong to a sub-loop, and it dominates the latch of the loop).
</li></ul>

</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Loop-manipulation.html">Loop manipulation</a>, Previous: <a href="Loop-representation.html">Loop representation</a>, Up: <a href="Loop-Analysis-and-Representation.html">Analysis and Representation of Loops</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
